今天要改善不同行動的執行間隔和判斷
並加入血量UI
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class monstercontrol : MonoBehaviour
{
int hp = 0;
public int max_hp = 0;
public GameObject hp_bar;
private Transform mytransform;
private Transform playertransform;
...
}
void Start()
{
rig = GetComponent<Rigidbody2D>();
max_hp = 10;
hp = max_hp;
...
}
private void FixedUpdate()
{
if (hp <= 0) {
Destroy(this.gameObject);
}
hp_bar.transform.localScale = new Vector3(((float)hp / (float)max_hp), hp_bar.transform.localScale.y, hp_bar.transform.localScale.z);
...
}
在Inspector的腳本會出現可以放入血量UI和設定血量的欄位
簡易計數每五秒執行一次
private float time1 = 5f;
private void FixedUpdate()
{
if (time1 <= 0)
{
//要執行的功能
time1 = 5;
}
time1 -= Time.deltaTime;
}
待更
有一些BUG跟功能要規劃判斷順序會花點時間
參考資料:
https://www.youtube.com/watch?v=dX1ICR6ZVWw